<?php

if(!empty($_POST)){
	include ("peditresource.php");
}else{
define("ROOT_PATH",str_replace("admin","",dirname($_SERVER['PHP_SELF'])));

$sids = $_SESSION["ArraySec"];


$rid = $_GET["rid"];
$sql = "SElect * from tblresource where id = $rid";
$rs = mysql_query($sql);
$resource =mysql_fetch_object($rs); 
?>
<script type="text/javascript" src="<?php echo ROOT_PATH."ckfinder/ckfinder.js"?>">
</script>
<script type="text/javascript">
function editResource(){
	var frm = document.frmEditResource;

	var vi_name = frm.vi_name.value;
	var en_name = frm.en_name.value;
	var link = frm.link.value;
	var msg= "";
	
	
	if(vi_name==""){
		msg+="Thiếu tên tài nguyên trong Tiếng Việt.\n";
	}
	if(en_name==""){
		msg+="Thiếu tên tài nguyên trong Tiếng Anh.\n";
	}
	
	
	if(link==""){
		msg+="Thiếu liên kết của tài nguyên.\n";
	}
	if(msg!=""){
		alert(msg);
	}else{
		frm.submit();
	}
}
function BrowseServer()
{
	// You can use the "CKFinder" class to render CKFinder in a page:
	var finder = new CKFinder() ;
	finder.basePath = '<?php echo str_replace("admin","",ROOT_PATH)."ckfinder/";?>' ;	// The path for the installation of CKFinder (default = "/ckfinder/").
	
	finder.selectActionFunction = function(fileUrl){
		
		document.getElementById( 'link' ).value = fileUrl ;
		//document.getElementById( 'img' ).src = fileUrl;
		
	}
	finder.popup() ;

	
}
</script>
<form name="frmEditResource" method="post">
	<table>
		<tr><th colspan="2" style="height:30px;background: #008000; color: white;">Sửa tài nguyên</th></tr>
		
		<tr>
			<td>
				<b>Tên Tiếng Việt</b>
			</td>
			<td>
				<input type="text" name="vi_name" size="60" value="<?php echo $resource->vi_name;?>"></input>
			</td>
		</tr>
		<tr>
			<td>
				<b>Tên Tiếng Anh</b>
			</td>
			<td>
				<input type="text" name="en_name" size="60" value="<?php echo $resource->en_name;?>"></input>
			</td>
		</tr>

		<tr>
			<td>
				<b>Link</b>
			</td>
			<td>
				<input type="text" id="link" name="link" size="60" value="<?php echo $resource->link;?>"></input>
				<input type="button" name="btnBrowser" value="Chọn file" onclick="BrowseServer();" />
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<input type="button" onclick="editResource();" value="Lưu"></input>
				<input type="reset"  value="Làm lại"></input> 
			</td>
		</tr>
	</table>
</form>
<?php }?>
